package com.ruoyi.projects.controller;

import java.util.List;

import com.ruoyi.common.constant.BuConstants;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.projects.domain.WechatConfig;
import com.ruoyi.projects.service.IWechatConfigService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小程序、商户相关配置Controller
 * 
 * @author ruoyi
 * @date 2022-01-06
 */
@RestController
@RequestMapping("/projects/WechatConfig")
public class WechatConfigController extends BaseController
{
    @Autowired
    private IWechatConfigService wechatConfigService;

    /**
     * 查询小程序、商户相关配置列表
     */
    @PreAuthorize("@ss.hasPermi('projects:WechatConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(WechatConfig wechatConfig)
    {
        startPage();
        List<WechatConfig> list = wechatConfigService.selectWechatConfigList(wechatConfig);
        return getDataTable(list);
    }

    /**
     * 获取小程序、商户相关配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('projects:WechatConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wechatConfigService.selectWechatConfigById(id));
    }

    /**
     * 修改小程序、商户相关配置
     */
    @PreAuthorize("@ss.hasPermi('projects:WechatConfig:edit')")
    @Log(title = "小程序、商户相关配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WechatConfig wechatConfig)
    {
        int i = wechatConfigService.updateWechatConfig(wechatConfig);
        if (i>0){
            return toAjax(i);
        }
        return AjaxResult.error("修改失败");
    }
}
